package com.haiyu.manager.controller.platform;

import com.haiyu.manager.dto.OrderSearchDTO;
import com.haiyu.manager.dto.orderStatusDTO;
import com.haiyu.manager.pojo.Order;
import com.haiyu.manager.response.PageDataResult;
import com.haiyu.manager.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("order")//指定路由
public class OrderController {
    @Autowired
    OrderService orderService;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     *
     * 功能描述: 跳到order列表
     *
     *
     */
    @RequestMapping("/orderManage")
    public String orderManage() {
        return "/order/orderManage";
    }

    /**
     *
     * 功能描述: 分页查询order列表
     *
     *
     */
    @RequestMapping(value = "/getOrderList", method = RequestMethod.POST)
    @ResponseBody
    public PageDataResult getOrderList(@RequestParam("pageNum") Integer pageNum,
                                       @RequestParam("pageSize") Integer pageSize,/*@Valid PageRequest page,*/ OrderSearchDTO orderSearch) {
        /*logger.info("分页查询用户列表！搜索条件：userSearch：" + userSearch + ",pageNum:" + page.getPageNum()
                + ",每页记录数量pageSize:" + page.getPageSize());*/
        System.out.println(orderSearch);
        PageDataResult pdr = new PageDataResult();
        try {
            if(null == pageNum) {
                pageNum = 1;
            }
            if(null == pageSize) {
                pageSize = 10;
            }
            // 获取order列表
            pdr = orderService.getOrderList(orderSearch, pageNum ,pageSize);
            logger.info("order列表查询=pdr:" + pdr);

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("order列表查询异常！", e);
        }
        return pdr;
    }


    /**
     *
     * 功能描述: 更新order
     *
     *
     */
    @RequestMapping(value = "/setOrder", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> setOrder(Order order) {
        logger.info("设置Order[更新]！Order:" + order);
        order.setOrderStatus(3);
        System.out.println(order);
        Map<String,Object> data = new HashMap();

        data = orderService.updateOrder(order);
        return data;
    }

    @GetMapping("getOrderStatus")
    @ResponseBody
    public List<orderStatusDTO> getOrderStatus(){
        orderStatusDTO orderStatusDTO0 = new orderStatusDTO();
        orderStatusDTO orderStatusDTO1 = new orderStatusDTO();
        orderStatusDTO orderStatusDTO2 = new orderStatusDTO();
        orderStatusDTO orderStatusDTO3 = new orderStatusDTO();


        orderStatusDTO0.setOrderStatus(0);
        orderStatusDTO0.setName("已下单");
        orderStatusDTO1.setOrderStatus(1);
        orderStatusDTO1.setName("已接单");
        orderStatusDTO2.setOrderStatus(2);
        orderStatusDTO2.setName("已完成");
        orderStatusDTO3.setOrderStatus(3);
        orderStatusDTO3.setName("已取消");
        List<orderStatusDTO> orderStatusDTOS = new ArrayList<orderStatusDTO>();
        orderStatusDTOS.add(orderStatusDTO0);
        orderStatusDTOS.add(orderStatusDTO1);
        orderStatusDTOS.add(orderStatusDTO2);
        orderStatusDTOS.add(orderStatusDTO3);
        return  orderStatusDTOS;
    }






}
